package com.mobile.collect.view;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.mobile.collect.R;

import java.util.ArrayList;
import java.util.List;

import cn.droidlover.xdroidmvp.base.BaseRecyclerAdapter;
import cn.droidlover.xdroidmvp.base.ListViewItemClickListener;
import cn.droidlover.xdroidmvp.base.RecyclerViewHolder;

/**
 * 类名: KeyBroadPop
 * 作者: 李学伟
 * 日期: 2020年09月22日 16:39
 * 描述: dialog_keybroad
 */
public class DimenDialog extends InputDialog {

    RecyclerView numberView;
    BaseRecyclerAdapter<String> numberAdapter;

    public DimenDialog(@NonNull Context context, String label, InputCompleteListener listener) {
        super(context, label, listener, R.layout.dialog_number, 0);
    }

    public DimenDialog(@NonNull Context context, String label,String oldtxt, InputCompleteListener listener) {
        super(context, label, oldtxt,listener, R.layout.dialog_number, 0);
    }

    @Override
    protected void initViews() {
        super.initViews();
        numberView = findViewById(R.id.numberView);
        numberView.setLayoutManager(new GridLayoutManager(context, 4));
        numberAdapter = new BaseRecyclerAdapter<String>(context) {
            @Override
            public int getItemLayoutId(int viewType) {
                return R.layout.item_latters;
            }

            @Override
            public void bindData(RecyclerViewHolder holder, int position) {
                super.bindData(holder, position);
                holder.setText(R.id.valueTv, getItemByPosition(position));
            }
        };
        numberView.setAdapter(numberAdapter);
        numberAdapter.addList(true, getTypes());

        numberAdapter.setItemClickListener(new ListViewItemClickListener() {
            @Override
            public void itemClick(int position) {
                if (position == numberAdapter.getItemCount()) {
                    del();
                }else{
                    completeListener.onInputComplete(numberAdapter.getItemByPosition(position));
                    dismiss();
                }


            }
        });
    }

    @Override
    protected void appendText(String value) {
        inputEt.setText(value);
    }

    private List<String> getTypes() {
        List<String> list = new ArrayList<>();
        list.add("0");
        list.add("10");
        list.add("15");
        list.add("20");
        list.add("25");
        list.add("40");
        list.add("50");
        list.add("65");
        list.add("80");
        list.add("100");
        list.add("150");
        list.add("200");
        list.add("250");
        list.add("300");
        list.add("350");
        list.add("400");
        list.add("450");
        list.add("500");
        list.add("600");
        list.add("700");
        list.add("800");
        list.add("900");
        list.add("1000");
        list.add("删除");
        return list;
    }

}
